{{!

  Copyright (c) Meta Platforms, Inc. and affiliates.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

}}{{!
Generated Python classes for abstract thrift-python types.
}}


{{> common/auto_generated_py}}

import abc as _abc
import typing as _typing
{{> fields/define_reserved_property_identifier}}
import builtins


{{#program:unions?}}
import enum as _enum

{{/program:unions?}}

import folly.iobuf as _fbthrift_iobuf
import {{program:base_library_package}}.abstract_types as _fbthrift_python_abstract_types
{{#program:include_namespaces}}
{{#has_types?}}
import {{included_module_path}}.thrift_abstract_types as {{included_module_mangle}}__thrift_abstract_types
{{/has_types?}}
{{/program:include_namespaces}}
{{#program:adapter_type_hint_modules}}
import {{module_path}}
{{/program:adapter_type_hint_modules}}
{{> types/import_enums}}
{{#program:structs}}

class {{> structs/unadapted_name}}({{!
        }}{{^struct:exception?}}_abc.ABC{{/struct:exception?}}{{!
        }}{{#struct:exception?}}_fbthrift_python_abstract_types.AbstractGeneratedError{{/struct:exception?}}):
    {{#struct:fields_ordered_by_id}}
    {{^field:is_invariant_type?}}
{{!
    This (mis-)alignment is necessary to ensure that the abstract method annotation aligns with the def on the next line
    and produces no output in the cases where it should not exist (currently for exceptions).
}}
{{> fields/use_reserved_property_identifier}}
{{> fields/maybe_abstract_method_annotation}}
    def {{field:py_name}}(self) -> {{> fields/field_type_pyi}}: ...
    {{/field:is_invariant_type?}}
    {{/struct:fields_ordered_by_id}}
    {{^struct:union?}}
    {{^struct:has_invariant_field?}}
{{> fields/maybe_abstract_method_annotation}}
    def __iter__(self) -> {{> types/iter_return_type}}: ...
    {{/struct:has_invariant_field?}}
    {{/struct:union?}}
    {{#struct:legacy_api?}}
{{> fields/maybe_abstract_method_annotation}}
    def _to_mutable_python(self) -> "{{program:module_path}}.thrift_mutable_types.{{> structs/unadapted_name}}": ...  # type: ignore
{{> fields/maybe_abstract_method_annotation}}
    def _to_python(self) -> "{{program:module_path}}.thrift_types.{{> structs/unadapted_name}}": ...  # type: ignore
{{> fields/maybe_abstract_method_annotation}}
    def _to_py3(self) -> "{{program:module_path}}.types.{{> structs/unadapted_name}}": ...  # type: ignore
{{> fields/maybe_abstract_method_annotation}}
    def _to_py_deprecated(self) -> "{{program:py_deprecated_module_path}}.ttypes.{{> structs/unadapted_name}}": ...  # type: ignore
    {{/struct:legacy_api?}}
    {{#struct:union?}}

    class FbThriftUnionFieldEnum(_enum.Enum):
        EMPTY = 0
    {{#struct:fields_ordered_by_id}}
        {{field:py_name}} = {{field:id}}
    {{/struct:fields_ordered_by_id}}

    {{! For backwards compatibility, set the name to the name
        used in immutable thrift-python, which is the name
        of the Union (sigh!)
    }}FbThriftUnionFieldEnum.__name__ = "{{struct:py_name}}"
    {{^struct:has_invariant_field?}}
{{> fields/use_reserved_property_identifier}}
{{> fields/maybe_abstract_method_annotation}}
    def fbthrift_current_value(self) -> {{> types/field_value_pep484_union_type}}: ...
    {{/struct:has_invariant_field?}}
{{> fields/use_reserved_property_identifier}}
{{> fields/maybe_abstract_method_annotation}}
    def fbthrift_current_field(self) -> FbThriftUnionFieldEnum: ...

    {{/struct:union?}}
{{#struct:has_adapter?}}

{{struct:py_name}} = {{adapter:type_hint}}{{#adapter:is_generic?}}[{{> structs/unadapted_name}}]{{/adapter:is_generic?}}
{{/struct:has_adapter?}}
{{> private/alias_prefix}}{{struct:py_name}} = {{struct:py_name}}{{!
}}{{/program:structs}}
{{#program:typedefs?}}

{{#program:typedefs}}
{{typedef:name}} = {{#typedef:has_adapter?}}{{!
    }}{{adapter:type_hint}}{{#adapter:is_generic?}}[{{#typedef:type}}{{> types/typedef_pep484_type}}{{/typedef:type}}]{{/adapter:is_generic?}}{{!
}}{{/typedef:has_adapter?}}{{!
}}{{^typedef:has_adapter?}}{{!
    }}{{#typedef:type}}{{> types/typedef_pep484_type}}{{/typedef:type}}{{!
}}{{/typedef:has_adapter?}}
{{/program:typedefs}}
{{/program:typedefs?}}
